home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / REXP.H < prev    next >
C/C++ Source or Header  |  1991-10-05  |  4KB  |  178 lines

  1.  
  2. /********************************************
  3. rexp.h
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13. /*$Log:    rexp.h,v $
  14.  * Revision 3.4  91/08/13  09:10:02  brennan
  15.  * VERSION .9994
  16.  * 
  17.  * Revision 3.3  91/06/15  09:40:25  brennan
  18.  * gcc defines __STDC__ but might not have stdlib.h
  19.  * 
  20.  * Revision 3.2  91/06/10  16:18:19  brennan
  21.  * changes for V7
  22.  * 
  23.  * Revision 3.1  91/06/07  10:33:18  brennan
  24.  * VERSION 0.995
  25.  * 
  26.  * Revision 1.3  91/06/05  08:57:57  brennan
  27.  * removed RE_xmalloc()
  28.  * 
  29.  * Revision 1.2  91/06/03  07:23:26  brennan
  30.  * changed type of RE_error_trap
  31.  * 
  32.  * Revision 1.1  91/06/03  07:05:41  brennan
  33.  * Initial revision
  34.  * 
  35. */
  36.  
  37. #ifndef  REXP_H
  38. #define  REXP_H
  39.  
  40. #ifdef THINK_C
  41. #define MAWK        /* THINK C doesn't allow compile-time definitions */
  42. #define SIZE_T(x) (size_t)(x)
  43. #endif
  44.  
  45. #ifndef SIZE_T
  46. #define SIZE_T(x) (x)
  47. #endif
  48.  
  49. #include  <stdio.h>
  50. #include  <setjmp.h>
  51.  
  52. char *strchr() ;
  53.  
  54. #ifndef   PROTO
  55. #ifdef    __STDC__
  56. #define  PROTO(name, args)   name  args
  57. #else
  58. #define  PROTO(name, args)   name()
  59. #endif
  60. #endif   
  61.  
  62. #ifdef  __STDC__
  63. #define  VOID   void
  64. #else
  65. #define  VOID   char
  66. #endif
  67.  
  68. VOID  *malloc(), *realloc() ;
  69. void free() ;
  70.  
  71.  
  72. VOID  *PROTO( RE_malloc, (unsigned) ) ;
  73. VOID  *PROTO( RE_realloc, (void *,unsigned) ) ;
  74.  
  75.  
  76. /*  finite machine  state types  */
  77.  
  78. #define  M_STR         0
  79. #define  M_CLASS       1
  80. #define  M_ANY         2
  81. #define  M_START       3
  82. #define  M_END         4
  83. #define  M_U           5
  84. #define  M_1J          6
  85. #define  M_2JA         7
  86. #define  M_2JB         8
  87. #define  M_ACCEPT      9
  88. #define  U_ON          10
  89.  
  90. #define  U_OFF     0
  91. #define  END_OFF   0
  92. #define  END_ON    (2*U_ON)
  93.  
  94.  
  95. typedef  unsigned char BV[32] ;  /* bit vector */
  96.  
  97. typedef  struct
  98. { char type ;
  99.   unsigned char  len ;  /* used for M_STR  */
  100.   union
  101.    { 
  102.      char *str  ;  /* string */
  103.      BV   *bvp ;   /*  class  */
  104.      int   jump ;
  105.    }  data ;
  106. }     STATE  ;
  107.  
  108. #define  STATESZ  (sizeof(STATE))
  109.  
  110. typedef  struct
  111. { STATE  *start, *stop ; }   MACHINE ;
  112.  
  113.  
  114. /*  tokens   */
  115. #define  T_OR   1       /* | */
  116. #define  T_CAT  2       
  117. #define  T_STAR 3       /* * */
  118. #define  T_PLUS 4       /* + */
  119. #define  T_Q    5       /* ? */
  120. #define  T_LP   6       /* ( */
  121. #define  T_RP   7       /* ) */
  122. #define  T_START 8      /* ^ */
  123. #define  T_END  9       /* $ */
  124. #define  T_ANY  10      /* . */
  125. #define  T_CLASS 11     /* starts with [ */
  126. #define  T_SLASH 12     /*  \  */
  127. #define  T_CHAR  13     /* all the rest */
  128. #define  T_STR   14
  129. #define  T_U     15
  130.  
  131. /*  precedences and error codes  */
  132. #define  L   0
  133. #define  EQ  1
  134. #define  G   2
  135. #define  E1  (-1)
  136. #define  E2  (-2)
  137. #define  E3  (-3)
  138. #define  E4  (-4)
  139. #define  E5  (-5)
  140. #define  E6  (-6)
  141. #define  E7  (-7)
  142.  
  143. #define  MEMORY_FAILURE      5
  144.  
  145. /* struct for the run time stack */
  146. typedef struct {
  147. STATE *m ;   /*   save the machine ptr */
  148. int    u ;   /*   save the u_flag */
  149. char  *s ;   /*   save the active string ptr */
  150. char  *ss ;  /*   save the match start -- only used by REmatch */
  151. } RT_STATE ;   /* run time state */
  152.  
  153. /*  error  trap   */
  154. extern int REerrno ;
  155. void   PROTO(RE_error_trap, (int) ) ;
  156.  
  157.  
  158. MACHINE   PROTO( RE_u, (void) ) ;
  159. MACHINE   PROTO( RE_start, (void) ) ;
  160. MACHINE   PROTO( RE_end, (void) ) ;
  161. MACHINE   PROTO( RE_any, (void) ) ;
  162. MACHINE   PROTO( RE_str, (char *, unsigned) ) ;
  163. MACHINE   PROTO( RE_class, (BV *) ) ;
  164. void      PROTO( RE_cat, (MACHINE *, MACHINE *) ) ;
  165. void      PROTO( RE_or, (MACHINE *, MACHINE *) ) ;
  166. void      PROTO( RE_close, (MACHINE *) ) ;
  167. void      PROTO( RE_poscl, (MACHINE *) ) ;
  168. void      PROTO( RE_01, (MACHINE *) ) ;
  169. void      PROTO( RE_panic, (char *) ) ;
  170. char     *PROTO( str_str, (char *, char *, unsigned) ) ;
  171.  
  172. void      PROTO( RE_lex_init , (char *) ) ;
  173. int       PROTO( RE_lex , (MACHINE *) ) ;
  174. void      PROTO( RE_run_stack_init, (void) ) ;
  175. RT_STATE *PROTO( RE_new_run_stack, (void) ) ;
  176.  
  177. #endif   /* REXP_H  */
  178.